package czk.concrent.waitandnotify;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/5/17 21:49
 */
public class Test3 {
    public static void main(String[] args) {
        //
         Object obj=new Object();
        Thread t1 = new Thread(() -> {
            System.out.println("t1..start");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            System.out.println("t1...end");
        }, "t1");
        t1.start();
        Thread t2 = new Thread(() -> {
            synchronized (t1) {
                try {
                    System.out.println("t2...start");
                    while (t1.isAlive()) {
                        System.out.println(t1.isAlive());
                        System.out.println("t2阻塞");
                        t1.wait();
                        System.out.println("t2解阻塞");
                    }
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
                System.out.println("t2...end");
            }
        }, "t2");
        t2.start();
    }
}
